package com.p2p.front.util;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.p2p.front.enums.BorrowAuth;

/**
 * leiwen@yiqihao.com
 */
public class BorrowerAuthUtil {

	/**
	 * auth字符串存储格式：idcard=1,house=1,edu=0
	 */
	public static String paramsToAuth(Map<String, Object> params) {
		if (params == null) {
			return "";
		}
		String str = "";
		for (Map.Entry<String, Object> entry : params.entrySet()) {
			str += "," + entry.getKey() + "=" + entry.getValue();
		}
		if (str.length() > 0) {
			str = str.substring(1);
		}
		return str;
	}

	public static Map<String, Object> authToParams(String auth) {
		if (StringUtils.isBlank(auth)) {
			return null;
		}
		String[] array = auth.split(",");
		Map<String, Object> params = new HashMap<String, Object>();
		for (String str : array) {
			String[] kvArray = str.split("=");
			if (kvArray.length == 2) {
				params.put(kvArray[0], kvArray[1]);
			}
		}
		return params;
	}
	
	public static String getDefaultValue(){
		return "idcard=1,job=1,credit=1,income=1,house=1,car=1,marriage=1,edu=1,address=1,indeed=1";
	}

	public static void main(String[] args) {
		StringBuilder sb = new StringBuilder();
		for(BorrowAuth auth:BorrowAuth.values()){
			sb.append(auth.name()).append("=1,");
		}
		sb.substring(0, sb.length()-1);
		System.out.println(sb.toString());
	}
}
